package com.android.vgongyi.activity;

import java.util.ArrayList;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.ListView;
import android.widget.Toast;

import com.android.vgongyi.R;
import com.android.vgongyi.common.FavorateAdapter;
import com.android.vgongyi.dao.FavorateDAO;
import com.android.vgongyi.entity.CommonEntity;


public class FavoriteActivity extends BaseActivity{
	
	private ArrayList<CommonEntity> favorateList;
	private FavorateAdapter favorateAdapter;
	private FavorateDAO favorateDAO ;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.favorite);
        
        setCommonTitle(this, R.string.favorite_title);
        
        ListView favoriteListView = (ListView) this.findViewById(R.id.favolist);
        
    	favorateDAO = new FavorateDAO(getApplicationContext());
    	favorateList = favorateDAO.query(null, null, null,null);
    	favorateAdapter = new FavorateAdapter(favorateList,this,favoriteListView,mHandler);
        favoriteListView.setAdapter(favorateAdapter);
        
        View emptyView = findViewById(R.id.favoEmptyText);
        
        if(favorateList.size()>0)  emptyView.setVisibility(View.GONE);
        else					   emptyView.setVisibility(View.VISIBLE);
        
        
    }
    
    @Override
    protected void onResume() {
    	super.onResume();
    	super.MenuDirectionConfig(this);
    }
    
    private Handler mHandler = new Handler() {  
        
        public void handleMessage(Message msg) {  
        	
        	favorateList.clear();
        	favorateList.addAll(favorateDAO.query(null, null, null,null));
        	favorateAdapter.notifyDataSetChanged();  
        	
        	View emptyView = findViewById(R.id.favoEmptyText);
            if(favorateList.size()>0)  emptyView.setVisibility(View.GONE);
            else					   emptyView.setVisibility(View.VISIBLE);
        	Toast.makeText(FavoriteActivity.this,getResources().getString(R.string.favorite_dec), Toast.LENGTH_SHORT).show();
        
        }  
    };  
      
    public void onDestroy() {  
        mHandler.removeMessages(0);  
        super.onDestroy();  
    }  
    
    
    
    
}
